import Vue from "vue"
import Vuex from "vuex"
import geo from "./modules/geo"
import home from "./modules/home"
import search from './modules/search'
import lang from './modules/lang'
Vue.use(Vuex)
const cookieparser = process.server ? require('cookieparser') : undefined

export const  modules={
    geo,
    home,
    search,
    lang
  }
  export const actions= {
    async nuxtServerInit({commit}, {req, app}) {
      console.log(1)
      {
        let auth = null
        if(req.headers.cookie){
          const parsed = cookieparser.parse(req.headers.cookie)
          console.log(parsed)
          try {
            auth = JSON.parse(parsed.auth)
          } catch (err) {
        console(1)
            // 找不到有效的Cookie
          }
        }
        commit('geo/setAuth',auth )
      }
    
    }
  }

